package com.jzy.gulimall.search.controller;

import com.jzy.gulimall.search.service.MallSearchService;
import com.jzy.gulimall.search.vo.SearchParam;
import com.jzy.gulimall.search.vo.SearchResp;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author jzy
 * @date 2020/9/14 12:43
 */
@Controller
public class SearchController {

    @Resource
    private MallSearchService mallSearchService;

    /**
     *  首页/搜索页  条件搜索
     */
    @GetMapping("/list.html")
    public String toListPage(SearchParam searchParam, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResp searchResp = mallSearchService.search(searchParam);
        model.addAttribute("result", searchResp);
        return "list";
    }
}
